package dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import vo.GoodsInfo;
import vo.VipInfo;
import dao.IGoodsDAO;
import dao.IVipDAO;

public class VipDAO extends BaseDAO implements IVipDAO {

	@Override
	public List getVip() {
		Session session = getSession();
		Query query = session.createQuery("from VipInfo v");
		List goods = query.list();
		session.close();
		return goods;

	}

	@Override
	public void addVip(VipInfo vipinfo) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		session.save(vipinfo);
		tx.commit();
		session.close();
	}

	@Override
	public void deleteVip(VipInfo vipinfo) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		session.delete(vipinfo);
		tx.commit();
		session.close();
	}

	@Override
	public void updateVip(VipInfo vipinfo) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		session.update(vipinfo);
		tx.commit();
		session.close();
	}

	@Override
	public VipInfo findVipById(int vipId) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		VipInfo vipinfo = null;
		vipinfo = (VipInfo) session.get(VipInfo.class, vipId);
		tx.commit();
		session.close();
		return vipinfo;

	}

	@Override
	public List searchVip(String hql) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Query query = session.createQuery(hql);
		List vip = query.list();
		session.close();
		return vip;
	}

	@Override
	public List findAllCustomer(int page, int rows) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Query query = session.createQuery("from VipInfo v");
		int startRow = (page - 1) * rows;
		query.setFirstResult(startRow);
		query.setMaxResults(rows);
		List vip = query.list();
		session.close();
		return vip;
	}

	@Override
	public int getTotalNumVip() {
		// TODO Auto-generated method stub
		Session session = getSession();
		Query query = session.createQuery("from VipInfo v");
		List vip = query.list();
		int Num = vip.size();
		session.close();
		return Num;
	}

}
